Skip to content

Conversation

@joshua-spacetime
Copy link
Collaborator

@joshua-spacetime joshua-spacetime commented Oct 17, 2025

Description of Changes

Adds the #[view] procedural macro and module describers for views.

#[view(public)]
fn player(ctx: &ViewContext) -> Vec<Player> {
    ctx.db.player().identity().find(ctx.sender).into_iter().collect()
}

#[view(public)]
fn player(ctx: &AnonymousViewContext, level: u32) -> Vec<Player> {
    ctx.db.player().level().filter(level).collect()
}

Note, this deviates from the proposal in that views may only return Vec<T> or Option<T>. They can't return an arbitrary SpacetimeType.

API and ABI breaking changes

This technically isn't a breaking change, but it's worth mentioning that this patch refactors ReducerInfo so that we can use it for views as well.

Expected complexity level and risk

2

Testing

  • Negative compile tests
  • Negative publish (module validation) tests
  • Test system tables are updated accurately

@bfops bfops added the release-any To be landed in any release window label Oct 20, 2025
@Centril Centril self-requested a review October 20, 2025 17:37
@joshua-spacetime joshua-spacetime changed the base branch from joshua/module-defs-for-views to master October 21, 2025 03:27
@joshua-spacetime joshua-spacetime changed the base branch from master to joshua/module-defs-for-views October 21, 2025 03:28
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch from 73ed5f9 to 6a8d021 Compare October 21, 2025 03:34
@joshua-spacetime joshua-spacetime changed the base branch from joshua/module-defs-for-views to master October 21, 2025 03:35
@joshua-spacetime joshua-spacetime removed the request for review from cloutiertyler October 21, 2025 03:36
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch 6 times, most recently from 2ecd24d to 8a11196 Compare October 22, 2025 00:34
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch from 8a11196 to 6eebf6e Compare October 22, 2025 06:46
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch from 6eebf6e to b52a38a Compare October 22, 2025 06:53
Copy link
Contributor

@gefjon gefjon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed out-of-band, it would be nice to have a test that the v9 validator rejects using a view as a scheduled function. Otherwise looks great!

Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this after the meeting. It looks good. I think we can improve things a bit but we can do that later. Let's add the join example though.

@joshua-spacetime joshua-spacetime added this pull request to the merge queue Oct 22, 2025
Merged via the queue into master with commit 0d325b2 Oct 22, 2025
25 of 26 checks passed
@joshua-spacetime joshua-spacetime deleted the joshua/view-macro-bindings branch October 22, 2025 21:22
bfops added a commit that referenced this pull request Oct 30, 2025
bfops added a commit that referenced this pull request Oct 31, 2025
bfops added a commit that referenced this pull request Oct 31, 2025
bfops added a commit that referenced this pull request Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants